﻿Public Class TMyTables
    Inherits TCustomMyObjects

    Friend Sub New(ByVal AOwner As TMyDatabase)
        MyBase.New(AOwner)
    End Sub

    Public Overrides Sub Refresh()
        Dim item As TMyTable
        _List.Clear()
        MyQuery.Clear()
        MyQuery.SQL.AppendLine("select")
        MyQuery.SQL.AppendLine(" table_catalog")
        MyQuery.SQL.AppendLine(",table_schema")
        MyQuery.SQL.AppendLine(",table_name")
        MyQuery.SQL.AppendLine(",table_type")
        MyQuery.SQL.AppendLine(",engine")
        MyQuery.SQL.AppendLine(",version")
        MyQuery.SQL.AppendLine(",row_format")
        MyQuery.SQL.AppendLine(",table_rows")
        MyQuery.SQL.AppendLine(",avg_row_length")
        MyQuery.SQL.AppendLine(",data_length")
        MyQuery.SQL.AppendLine(",max_data_length")
        MyQuery.SQL.AppendLine(",index_length")
        MyQuery.SQL.AppendLine(",data_free")
        MyQuery.SQL.AppendLine(",auto_increment")
        MyQuery.SQL.AppendLine(",create_time")
        MyQuery.SQL.AppendLine(",update_time")
        MyQuery.SQL.AppendLine(",check_time")
        MyQuery.SQL.AppendLine(",table_collation")
        MyQuery.SQL.AppendLine(",checksum")
        MyQuery.SQL.AppendLine(",create_options")
        MyQuery.SQL.AppendLine(",table_comment")
        MyQuery.SQL.AppendLine("from")
        MyQuery.SQL.AppendLine(" information_schema.tables")
        MyQuery.SQL.AppendLine("where")
        MyQuery.SQL.AppendLine("table_schema=?table_schema")
        MyQuery.SQL.AppendLine("and table_type like '%TABLE%'")
        MyQuery.SQL.AppendLine("order by")
        MyQuery.SQL.AppendLine(" table_name")
        MyQuery.DeclareAndSet("table_schema", Me.DatabaseName)
        MyQuery.Execute()
        While Not MyQuery.Eof
            item = New TMyTable(Me, MyQuery.FieldAsString("table_name"))
            item._TableCatalog = MyQuery.FieldAsString("table_catalog")
            item._TableSchema = MyQuery.FieldAsString("table_schema")
            item._TableName = MyQuery.FieldAsString("table_name")
            item._TableType = MyQuery.FieldAsString("table_type")
            item._Engine = MyQuery.FieldAsString("engine")
            item._Version = MyQuery.FieldAsInteger("version")
            item._RowFormat = MyQuery.FieldAsString("row_format")
            item._TableRows = MyQuery.FieldAsInteger("table_rows")
            item._AvgRowLength = MyQuery.FieldAsInteger("avg_row_length")
            item._DataLength = MyQuery.FieldAsInteger("data_length")
            item._MaxDataLength = MyQuery.FieldAsInteger("max_data_length")
            item._IndexLength = MyQuery.FieldAsInteger("index_length")
            item._DataFree = MyQuery.FieldAsInteger("data_free")
            item._AutoIncrement = MyQuery.FieldAsInteger("auto_increment")
            item._CreateTime = MyQuery.fieldasdatetime("create_time")
            item._UpdateTime = MyQuery.fieldasdatetime("update_time")
            item._CheckTime = MyQuery.fieldasdatetime("check_time")
            item._TableCollation = MyQuery.FieldAsString("table_collation")
            item._Checksum = MyQuery.FieldAsInteger("checksum")
            item._CreateOptions = MyQuery.FieldAsString("create_options")
            item._TableComment = MyQuery.FieldAsString("table_comment")
            _List.Add(item)
            MyQuery.MoveNext()
        End While
        MyQuery.Close()

    End Sub

End Class
